package com.demo.ext.user;

import com.demo.common.model.Blog;
import com.demo.util.JdbcUtils;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;

/**
 * @Author: linKe
 * @Date: 2022/4/11 15:10
 * @ClassName: ActiveRecordTest
 * @Version: 1.0
 * @Description:
 */
public class ActiveRecordTest {
    public static void main(String[] args) {
       /* String dirver = "com.mysql.cj.jdbc.Driver";
        String jdbcUrl = "jdbc:mysql://localhost/jfinal_demo?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull";
        String user = "root";
        String password = "123456";

        DruidPlugin dp = new DruidPlugin(jdbcUrl, user, password,dirver);
        */

        DruidPlugin dp = JdbcUtils.getDruidPlugin();
        ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
        arp.addMapping("blog", Blog.class);

        // 与 jfinal web 环境唯一的不同是要手动调用一次相关插件的start()方法
        dp.start();
        arp.start();

        // 通过上面简单的几行代码，即可立即开始使用
        new Blog().set("title", "title").set("content", "cxt text").save();
        Blog byId = new Blog().dao().findById(1);
        System.out.println(byId);
    }
}
